package com.doctcloud.hisystem.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doctcloud.hisystem.common.mapper.SysDictTypeEntityMapper;
import com.doctcloud.hisystem.common.service.ISysDictTypeEntityService;
import com.doctcloud.hisystem.tables.domain.common.SysDictTypeEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.math.BigInteger;
import java.util.List;

@Service
@Slf4j
public class SysDictTypeEntityServiceImpl extends ServiceImpl<SysDictTypeEntityMapper, SysDictTypeEntity> implements ISysDictTypeEntityService {

    /**
     * 项目启动时，初始化字典到缓存
     */
//    @PostConstruct
//    public void init()
//    {
//        loadingDictCache();
//    }
    @Override
    public List<SysDictTypeEntity> selectDictTypeList(SysDictTypeEntity dictType) {
        return baseMapper.select(dictType);
    }

    @Override
    public List<SysDictTypeEntity> selectDictTypeAll() {
        return baseMapper.selectAll();
    }

    @Override
    public List<SysDictTypeEntity> selectDictDataByType(String dictType) {
        return baseMapper.selectDictTypeByType(dictType);
    }

    @Override
    public SysDictTypeEntity selectDictTypeById(Long dictId) {
        return baseMapper.selectByPrimaryKey(dictId);
    }

    @Override
    public SysDictTypeEntity selectDictTypeByType(String dictType) {
        return null;
    }

    @Override
    public int deleteDictTypeByIds(List<Long> dictIds) {
        return baseMapper.deleteDictTypeByPrimaryKeys(dictIds);
    }

    @Override
    public void loadingDictCache() {
//        SysDictData dictData = new SysDictData();
//        dictData.setStatus("0");
//        Map<String, List<SysDictData>> dictDataMap = baseMapper.selectDictDataList(dictData).stream().collect(Collectors.groupingBy(SysDictData::getDictType));
//        for (Map.Entry<String, List<SysDictData>> entry : dictDataMap.entrySet())
//        {
//            DictUtils.setDictCache(entry.getKey(), entry.getValue().stream().sorted(Comparator.comparing(SysDictData::getDictSort)).collect(Collectors.toList()));
//        }
    }

    @Override
    public void clearDictCache() {

    }

    @Override
    public void resetDictCache() {

    }

    @Override
    public int insertDictType(SysDictTypeEntity dictType) {
        return baseMapper.insert(dictType);
    }

    @Override
    public int updateDictType(SysDictTypeEntity dictType) {
        return baseMapper.updateByPrimaryKey(dictType);
    }

    @Override
    public SysDictTypeEntity checkDictTypeUnique(String dictType) {
        return baseMapper.checkDictTypeUnique(dictType);
    }
}
